﻿<cfscript>
/** 
* ORM ExamResitTask
* 
* @hint "Hibernate persistenter t_resittask. 补考任务考试安排情况表" 
* 
*/ 

component 
	displayname="public.service.orm.senate.ExamResitTask" 
	output=false 
	persistent=true 
	selectBeforeUpdate=true dynamicInsert=true dynamicUpdate=true 
	cacheuse="Transactional" 
	entityname="ExamResitTask" 
	table="t_resittask"
	{
		
	property type="string" name="TaskResitExamID" column="task_exrstid" fieldtype="id" generator="assigned" hint="补考任务号";
		
	property type="numeric" name="ExamResitIndex" column="rstidx" hint="补考序号";

	property type="string" name="ExamWeek" column="wid" hint="考试周次";
	property type="string" name="ExamWeekDay" column="wdidx" hint="星期几";

	property type="string" name="TaskProgress" column="task_prog" hint="任务安排状态";
		
	property type="numeric" name="ExamSize" column="examer_sum" hint="考试人数";

	property name="Term" fieldtype="many-to-one" fkcolumn="term_id" cfc="Term"  hint="学期";
	property name="Course" fieldtype="many-to-one" fkcolumn="cid" cfc="Course"  hint="课程";
	property name="ExamCell" fieldtype="many-to-one" fkcolumn="cellidx" cfc="ExamCell"  hint="场次编号";
	property name="Campus" fieldtype="many-to-one" fkcolumn="campus_id" cfc="Campus" hint="校区代码";

	property name="StudentExamResiters" type="array" lazy="true" inverse="true" cascade="delete-orphan" fieldtype="one-to-many" fkcolumn="task_exrstid" cfc="StudentExamResit" hint="该场次考试学生";

	/**
	* @hint "生成补考序号"
	* 
	* @Term "学期"
	*/
	public string function getExamIDX( required Term ) output=false {
		
		/* 
			考序号规则 6位代码
		*/
		var nextID = numberFormat(1, "0_____");
			
		var checkArray = ORMExecuteQuery("select ExamResitIndex from ExamResitTask 
											where 
											Term = :term 
											order by ExamResitIndex desc", { term=arguments.Term }, { maxResults=1 });
			
		if (arrayLen(checkArray)) {
			/* 创建一个追加id */
			nextID = numberFormat((checkArray[1] + 1), "0_____");
		}

		return nextID;
	}
	
	/**
	* @hint "自定义主键规则"
	* 
	* @Term "学期"
	* @ExamResitIndex "补考序号"
	*/
	public string function getID( required Term, required string ExamResitIndex ) output=false {
		
		var nextID = arguments.Term.getTermID() & "R" & arguments.ExamResitIndex;

		/* 
			主键生成规则 
			
			考试任务号10位 3位学期代码 1位考试类别代码[R-补考] 6位考序号

			Unique: TERM_ID, RSTIDX
		*/
		return nextID;
	}

}
	
</cfscript>
